package com.hui.auth.config.shiro.filter;

import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * shiro跨域问题解决工具
 */
public class CrosUtil {

    public static void crosOrgin(HttpServletRequest request, HttpServletResponse response) {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        response.setHeader("Access-Control-Allow-Headers", "x-auth-token");
        response.setHeader("Access-Control-Allow-Methods", request.getMethod());
        response.setHeader("Access-Control-Allow-Credentials", "true");
        String origin = request.getHeader("Origin");
        if (StringUtils.isEmpty(origin)) {
            response.setHeader("Access-Control-Allow-Origin",
                    "http://127.0.0.1:8020,http://cltest.h5.rongshutong.com");
        } else {
            response.setHeader("Access-Control-Allow-Origin", origin);
        }
        response.setHeader("Access-Control-Expose-Headers", "x-auth-token");
        response.setHeader("Access-Control-Max-Age", "3600");
    }

}
